﻿// <copyright file="BlogEntryArchiveDynamicNodeProvier.cs" company="Clever Software">
// Copyright (c) 2013, 2014 All Right Reserved, http://www.cleversoftware.by
//
// This source is subject to the Microsoft Permissive License.
// Please see the License.txt file for more information.
// All other rights reserved.
//
// THIS CODE AND INFORMATION ARE PROVIDED "AS IS" WITHOUT WARRANTY OF ANY 
// KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
// PARTICULAR PURPOSE.
//
// </copyright>
// <author>Clever Software</author>
// <email>info@cleversoftware.by</email>
// <date>2014-02-04</date> 
// <summary>CleverCMS source code</summary>

namespace CleverCMS.Blog.Services.Infrastructure
{
    using System;   
    using System.Collections.Generic;

    using MvcSiteMapProvider;
    
    using Core.Infrastructure;
    using System.Globalization;

    public class BlogEntryArchiveDynamicNodeProvier : DynamicNodeProviderBase
    {
        private BlogEntryService m_blogEntryService;
        private readonly AppCache m_appCache;

        public BlogEntryArchiveDynamicNodeProvier()
        {
            m_appCache = new AppCache();
            m_blogEntryService = IoC.Get<BlogEntryService>();
        }


        public override IEnumerable<DynamicNode> GetDynamicNodeCollection(ISiteMapNode node)
        {
            var dates = m_blogEntryService.GetAllDates();
            var nodes = new List<DynamicNode>();
            
            foreach (var date in dates)
            {
                var entryNode = new DynamicNode { Key = "archiveEntry_" + Guid.NewGuid() };
                entryNode.RouteValues.Add("year",date.Year);
                entryNode.RouteValues.Add("month", date.Month);
                entryNode.Action = "archive";
                entryNode.Controller = "blog";
                entryNode.Title = date.ToString("MMM", CultureInfo.InvariantCulture) + " " + date.Year; 
                nodes.Add(entryNode);
            }

            return nodes;
        }
    }
}
